﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace WebAppDemo.Classes
{
    public class PersonList
    {
        public List<Person> GetList()
        {
            var list=new List<Person>();
            System.Collections.IDictionaryEnumerator cacheEnum = HttpContext.Current.Cache.GetEnumerator();
            while (cacheEnum.MoveNext())
            {
                var key=cacheEnum.Key.ToString();
                list.Add((Person)HttpContext.Current.Cache[key]);  
            }
            return list;
        }
       
        public void Add(Person p)
        {
            HttpContext.Current.Cache.Add(p.Name, p, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration,
                                          CacheItemPriority.High, null);
        }

        public void Remove(string name)
        {
            HttpContext.Current.Cache.Remove(name);
        }
    }
}